﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using com.crawler.common;
using com.crawler.components;

namespace Crawler_5
{
    public partial class CrawlerService : ServiceBase
    {
        public CrawlerService()
        {
            InitializeComponent();
        }
        System.Threading.Thread m_crawler_thd = null;
        protected override void OnStart(string[] args)
        {
            BookCrawManager t_book_mgr = new BookCrawManager();

            m_crawler_thd = new Thread(new ThreadStart(t_book_mgr.StartNewBook));
            if (m_crawler_thd != null)
            {
                m_crawler_thd.Start();

                LogHelper.Info("成功创建收录crawler的线程!");
            }
        }

        protected override void OnStop()
        {
            try
            {
                if (m_crawler_thd != null)
                {
                    m_crawler_thd.Abort();
                    LogHelper.Info("收录线程已经停止!");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("关闭线程失败" + ex.ToString());
            }
        }
    }
}
